﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using WaterBill.DTO;

namespace WaterBill.DAL
{
    class DAL_Nests : clsConnection
    {
        DataTable dtN;

        //Lay danh sach tat ca cac to
        public DataTable DAL_Nests_GetAll()
        {
            dtN = new DataTable();
            try
            {
                dtN = ExcuteQuery("GetAllNest");
            }
            catch
            {
            }
            return dtN;
        }

        //Lay danh sach cac to dua vao HamletId
        public DataTable DAL_Nests_GetByHamletId(int HamletId)
        {
            dtN = new DataTable();
            try
            {
                AddParameter(new SqlParameter("@HamletId", HamletId));
                dtN = ExcuteQuery("GetNestByHamletId");
            }
            catch
            {
            }
            return dtN;
        }

        //Them mot to moi vao ap
        public Boolean DAL_Nests_Insert(DTO_Nests obj)
        {
            try
            {
                AddParameter(new SqlParameter("@Name", obj.Name));
                AddParameter(new SqlParameter("@HamletId", obj.HamletId));
                AddParameter(new SqlParameter("@Status", 1));
                if (ExcuteNonQuery("InsertNest"))
                {
                    return true;
                }
            }
            catch
            {
            }
            return false;
        }

        //Sua to
        public Boolean DAL_Nests_Update(DTO_Nests obj)
        {
            try
            {
                AddParameter(new SqlParameter("@NestId", obj.NestId));
                AddParameter(new SqlParameter("@Name", obj.Name));
                AddParameter(new SqlParameter("@HamletId", obj.HamletId));
                AddParameter(new SqlParameter("@Status", obj.Status));
                if(ExcuteNonQuery("UpdateNest")){
                    return true;
                }
            }
            catch
            {
            }
            return false;
        }

        //Xoa to
        public Boolean DAL_Nests_Delete(int NestId)
        {
            try
            {
                AddParameter(new SqlParameter("@NestId", NestId));

                if (ExecuteScalar("DeleteNest") == 1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch
            {
            }
            return false;
        }
    }
}
